import Vue from "vue";
import App from "./App.vue";
import vuetify from "./plugins/vuetify";
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

// 全局公共组件
import global from './components/main/Common.vue'
Vue.prototype.COMMON = global

Vue.use(ElementUI)

// import MintUI from 'mint-ui'
// import 'mint-ui/lib/style.css'
// Vue.use(MintUI)

Vue.config.productionTip = false;
import VueRouter from "vue-router";

import routers from "./router";
import axios from "axios";
import "babel-polyfill";
import Icon from 'vue-svg-icon/Icon.vue';
import './assets/css/app.css';

// import Vue from 'vue'
import Vuetify from 'vuetify/lib'

Vue.use(Vuetify)

Vue.component('icon', Icon);
Vue.use(VueRouter);

const router = new VueRouter({
	mode: "hash",
	routes: routers
});

axios.interceptors.request.use(
	config => {
		//在所有请求头部添加CSRFToken值
		function getCookie(name) {
			let r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
			return r ? r[1] : undefined;
		}
		config.headers['X-CSRFToken'] = getCookie("token");
		return config;
	},
	error => {
		return Promise.reject(error);
	}
);
// // response 拦截器
// axios.interceptors.response.use(
//   response => {
//     return response;
//   },
//   error => {
//     if (error.response) {
//       localStorage.setItem("Authorization", null);
//       switch (error.response.data.msg) {
//         case "token已过期":
//           router.replace({
//             path: "/",
//             query: { redirect: router.currentRoute.fullPath }
//           });
//           break;
//         case "无效的token":
//           router.replace({
//             path: "/",
//             query: { redirect: router.currentRoute.fullPath }
//           });
//           break;
//
//         case "需要携带token值":
//           router.replace({
//             path: "/",
//             query: { redirect: router.currentRoute.fullPath }
//           });
//           break;
//         case "权限不足":
//           router.replace({
//             path: "/",
//             query: { redirect: router.currentRoute.fullPath }
//           });
//           break;
//       } //登录成功后跳入浏览的当前页面
//     }
//     return Promise.reject(error.response.data);
//   }
// );
new Vue({
	vuetify,
	router,
	render: h => h(App)
}).$mount("#app");
